﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Configuration;
using UFC.Common;

namespace MESArrangement
{
    public partial class Send_Arrangement : ServiceBase
    {

        private System.Timers.Timer m_SyncTimer;
        public Send_Arrangement()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            LogHelp.SetConfig();
            m_SyncTimer = new System.Timers.Timer();
            m_SyncTimer.Enabled = false;
            m_SyncTimer.Elapsed += new System.Timers.ElapsedEventHandler(m_SyncTimer_Elapsed);

            int intSync = Convert.ToInt32(ConfigurationManager.AppSettings["sync"].ToString());
            m_SyncTimer.Interval = intSync *10* 60 * 1000;
            m_SyncTimer.Enabled = true;
            m_SyncTimer.Start();
        }

        private void m_SyncTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            try
            {
               // LogHelp.WriteLog("Arrangement定时器启动");
                m_SyncTimer.Enabled = false;
                SendArrangementData runMain = new SendArrangementData();
                runMain.RunArrangementSync();
            }
            catch (Exception myError)
            {
                LogHelp.WriteError(myError.Message , myError);
            }
            finally
            {
                m_SyncTimer.Enabled = true;
            }
        }


        protected override void OnStop()
        {
       
        }
    }
}
